﻿Add-Type -TypeDefinition @"

  using System;
  using System.Diagnostics;

  public enum EventSeverityType
  {
    Null = 0,
    Debug = 100,
    Notice = 200,
    Warning = 300,
    Error = 500,
    Fatal = 1000
  }

  public class Event
  {
    public String SourceName;
    public EventSeverityType Severity;
    public uint EventNumber;
    public String Message;
    public String Details;

    public System.Guid UniqueId;
    public int SourcePID;
    public System.DateTime EventTime;
    public String ComputerName;
    public String UserName;
    
    public bool IsHandled;

    public Event(String Src, uint Num, EventSeverityType Sv, String Msg)
    {
      SourceName = Src;
      EventNumber = Num;
      Severity = Sv;
      Message = Msg;

      UniqueId = Guid.NewGuid();
      SourcePID = Process.GetCurrentProcess().Id;
      EventTime = DateTime.Now;
      ComputerName = System.Environment.MachineName;
      UserName = System.Environment.UserName;

      IsHandled = false;
    }

    public Event(String Src, uint Num, EventSeverityType Sv, String Msg, String Det)
    {
      SourceName = Src;
      EventNumber = Num;
      Severity = Sv;
      Message = Msg;
      Details = Det;

      UniqueId = Guid.NewGuid();
      SourcePID = Process.GetCurrentProcess().Id;
      EventTime = DateTime.Now;
      ComputerName = System.Environment.MachineName;
      UserName = System.Environment.UserName;

      IsHandled = false;
    }
  }

  public enum EventHandlerCategoryType
  {
    Null = 0,
    File,
    EventLog,
    Console
  }

  public enum EventFilterVariableType
  {
    Null = 0,
    SourceName,
    Severity,
    EventNumber,
    Message,
    Details,

    ComputerName,
    UserName,
    IsHandled
  }

  public enum EventFilterOperatorType
  {
    Null = 0,
    EQ,
    NE,
    GT,
    GE,
    LT,
    LE,
    LIKE,
    NOTLIKE
  }

  public class EventHandler
  {
    public uint Number;
    public System.Guid Id;
    public String FriendlyName;
    public EventHandlerCategoryType Category;

    public String LogEntryFormat;
    public String TimeStampFormat;

    public System.Collections.Hashtable SourceReplacementRegex;
    public System.Collections.Hashtable MessageReplacementRegex;
    public System.Collections.Hashtable DetailsReplacementRegex;

    public EventHandler()
    {
      Id = Guid.NewGuid();
    }

    public override bool Equals(Object obj)
    {
      EventHandler EventHandlerObj = obj as EventHandler;
      if (EventHandlerObj == null)
      {
        return false;
      }
      else
      {
        return Id.Equals(EventHandlerObj.Id);
      }
    }

    public override int GetHashCode()
    {
      return this.Id.GetHashCode();
    }
  }
 
  public class EventHandlerFile : EventHandler
  {
    public String LogPath;
  }

  public class EventHandlerEventLog : EventHandler
  {
    public String LogName;
  }

  public class EventHandlerConsole : EventHandler
  {
  }

  public class EventFilterCondition
  {
    public System.Guid Id;
    public uint Number;
    public EventFilterVariableType Variable;
    public EventFilterOperatorType Operator;
    public String Value;

    public EventFilterCondition()
    {
      Id = Guid.NewGuid();
    }
  }

  public class EventGroup
  {
    public uint Number;
    public System.Guid Id;
    public String FriendlyName;
    public uint Order;
    public String Description;
    public EventFilterCondition[] FilterConditions;
    public System.Guid[] AssignedHandlers;
    public bool IsEnabled;

    public EventGroup()
    {
      Id = Guid.NewGuid();
      IsEnabled = true;
    }

    public override bool Equals(Object obj)
    {
      EventGroup EventGroupObj = obj as EventGroup;
      if (EventGroupObj == null)
      {
        return false;
      }
      else
      {
        return Id.Equals(EventGroupObj.Id);
      }
    }

    public override int GetHashCode()
    {
      return this.Id.GetHashCode();
    }

  }

"@